//
//  UIBarButtonItem+Extension.swift
//  微博天下
//
//  Created by Tsz on 15/10/17.
//  Copyright © 2015年 Tsz. All rights reserved.

import UIKit

extension UIBarButtonItem{
    convenience init(imageName: String, target: AnyObject? , action: String?){
        let button = UIButton()
        button.setImage(UIImage(named: imageName), forState: UIControlState.Normal)
        //高量
        button.setImage(UIImage(named: imageName + "_highlighted"), forState: UIControlState.Highlighted)
        button.sizeToFit()
        //设置监听方法 ，判断action方法是否存在
        if let acctionName = action {
            button.addTarget(target, action: Selector(acctionName), forControlEvents: UIControlEvents.TouchUpInside)
        }
        
        //调用指定的函数
        self.init(customView: button)
    }
    

}
